package com.yunfeng.supercall.activity;

import org.json.JSONException;
import org.json.JSONObject;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.FrameLayout;

import com.yunfeng.supercall.R;
import com.yunfeng.supercall.app.AppContext;
import com.yunfeng.supercall.httputils.MyAjaxCallBack;

public class ResetPassStep2Activity extends BaseActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_reset_pass2);
		FrameLayout framelayoutBack = (FrameLayout) findViewById(R.id.framelayout_back);
		framelayoutBack.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});

	}

	public void submit(View view) {
		try {

			String pass = getTextViewText(R.id.pass);
			String repass = getTextViewText(R.id.repass);
			if (AppContext.isInvalidPassWord(pass)) {
				showToast(R.string.input_correct_pass);
				return;
			}
			if (TextUtils.isEmpty(repass)) {
				showToast(R.string.input_confirm_pass);
				return;
			}
			if (!pass.equals(repass)) {
				showToast(R.string.incorrect_pass);
				return;
			}
			JSONObject json = new JSONObject(getIntent().getStringExtra("data"));
			String phone = json.getString("i_phone");
			json = getBaseParams(getActivity());
			json.put("i_phone", phone);
			json.put("i_key", "");
			json.put("i_newpass", pass);
			showProgressDialog(R.string.editing);
			mHttpClient.post(FUNCTION_CHANGE_PASS, json, new MyAjaxCallBack() {

				@Override
				public void onReceiveError(String msg, String errorCode) {
					// TODO Auto-generated method stub
					showToast(msg);
					cancelProgressDialog();
				}

				@Override
				public void onReceiveData(String data, String msg) {
					// TODO Auto-generated method stub
					showToast(R.string.edit_success);
					cancelProgressDialog();
					finish();
				}
			});
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
